import {useState, useEffect} from 'react';
import {Select, message} from 'antd'
import {SelectEqType} from '@/services/equipment'

const SelectEquipmentType = (props: any) => {
  const {onChange} = props
  const [list, setList] = useState([]);
  const [value, setValue] = useState(null);
  useEffect(() => {
    SelectEqType({}).then(res => {
      if (res.status === 200) {
        setList(res.data)
      } else {
        message.error(res.message).then()
      }
    })
  }, [])
  return (
    <Select
      showSearch
      filterOption={(input, option) => option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
      allowClear
      value={value}
      autoClearSearchValue
      onChange={(e) => {
        onChange(e);
        setValue(e);
      }}
      placeholder={'请选择设备类型'}
    >
      {list.map(({equipment_type}) => (
        <Select.Option value={equipment_type}>{equipment_type}</Select.Option>
      ))}
    </Select>
  );
};

export default SelectEquipmentType;
